<template>
<<<<<<< HEAD
	<div class="singer" ref="singer">
	    <div class="wrapper">
	    	<list-view :data="singerList"></list-view>	
	    </div>
	    <router-view></router-view>
  	</div>
</template> 

<script>
	import { getSingerList } from 'api/singer'
	import Singer from 'assets/js/singer'
	import ListView from 'base/listView/listView'

	export default{
		data(){
			return {
				singerList:[]
			}
		},
		mounted(){
			this._getSingerList()
		},
		methods:{
			_getSingerList(){
				getSingerList().then((res)=>{
					// console.log(res)
					this.singerList = this._formatSingerList(res.data.list);
					// console.log(this.singerList)
				})
			},
			//进行数据处理(使用构造函数)
			_formatSingerList(list){
				 const HOT_NAME = '热门';
				 const HOT_LEN = 10

				//热门列表
				const map = {
					hot:{
						title:HOT_NAME,
						items:[]
					}
				}

				//对得到的数据进行分类
				list.forEach((item,index)=>{
					if(index<HOT_LEN){
						map.hot.items.push(new Singer(item.Fsinger_mid,item.Fsinger_name))
					}

					let key = item.Findex;
					if(!map[key]){
						map[key] = {
							title:item.Findex,
							items:[]
						} 
					}
					map[key].items.push(new Singer(item.Fsinger_mid,item.Fsinger_name))
				})
				let hot = [];
				let arr = [];
				// console.log(map)
				for(let i in map){
					// console.log(i)
					if (map[i].title == HOT_NAME) {
						hot.push(map[i])
					}else if(map[i].title.match(/[a-zA-Z]/))
					{
						arr.push(map[i])
					}
				}
				arr.sort((a,b)=>{
					return a.title.charCodeAt(0)-b.title.charCodeAt(0)
				})
				// console.log(hot,arr)
				return hot.concat(arr);
			}
		},
		components:{
			ListView
		}
	}
=======
  <div class="singer" ref="singer">
    <div class="wrapper">
    	<list-view :data="singerList"></list-view>	
    </div>
    <router-view></router-view>
  </div>
</template>

<script>
	import {getSingerList} from 'api/singer'
	import Singer from 'assets/js/singer'
	import ListView from 'base/listView/listView'

	const HOT_NAME = "热门"
	const HOT_LEN = 10

  	export default {
	  	data(){
	  		return {
	  			singerList:[]
	  		}
	  	},
	   	created(){
	   		this._getSingerList()
	   	},
	   	methods:{
	   		_getSingerList(){
	   			getSingerList().then((res)=>{
	   				this.singerList = this._formatSingerList(res.data.list)
	   			})
	   		},
	   		_formatSingerList(list){
	   			// 定义歌手列表的数据结构
	   			let map = {
	   				hot:{
	   					title:"热门",
	   					items:[]
	   				}
	   			}
	   			list.forEach((item,index)=>{
	   				// 前十条数据为热门数据
	   				if(index < HOT_LEN){
	   					// 创建一个singer实例，并且添加到items里面
	   					map.hot.items.push(new Singer(item.Fsinger_mid,item.Fsinger_name))
	   				}
	   				let key = item.Findex
	   				if(!map[key]){
	   					map[key] = {
	   						title:key,
	   						items:[]
	   					}
	   				}
	   				map[key].items.push(new Singer(item.Fsinger_mid,item.Fsinger_name))
	   			})
	   			// 对数据结构进行排序操作
	   			// 存放热门数据
	   			let hot = []
	   			// 存放a-z
	   			let arr = []
	   			for(let key in map){
	   				// 当为a-z是添加到arr
	   				if(map[key].title.match(/[a-zA-Z]/)){
	   					arr.push(map[key])
	   				}else if(map[key].title == HOT_NAME) {
	   					hot.push(map[key])
	   				}
	   			}
	   			// 对arr数组排序
	   			arr.sort((a,b)=>{
	   				return a.title.charCodeAt(0) - b.title.charCodeAt(0)
	   			})
	   			return hot.concat(arr)
	   		}
	   	},
	   	components:{
	   		ListView
	   	}
  	}
>>>>>>> 2f2681559102dd200f119afb607054cf37b8104a
</script>

<style scoped lang="less">
	.singer {
		position: fixed;
		width: 100%;
		top:88px;
		bottom:0;
		overflow: hidden;
		.wrapper {
			height: 100%;
			overflow: hidden;
		}
	}
</style>